// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FRIServerTest.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Test.Robotics.Hardware.KukaLBR.KukaLBR4Tests
{
    using System;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Test the functionality of the FRIServer class (software only tests)
    /// </summary>
    [TestClass]
    [DeploymentItem("Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll")]
    [DeploymentItem("Microsoft.Robotics.Hardware.KukaLBR.KukaLBR4Controller.dll")]
    [DeploymentItem("Microsoft.Robotics.Manipulation.ControllerStateMachine.dll")]
    public class FRIServerTest
    {
        /// <summary>
        /// Default size of result string
        /// </summary>
        private const int DefaultResultStringSize = 200;

        /// <summary>
        /// Test the basic functionality of the <c>DoNothing()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerDoNothingTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerDoNothingTest, "FRIServerDoNothingTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>DoPositionControl()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerDoPositionControlTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerDoPositionControlTest, "FRIServerDoPositionControlTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>WaitOnConnect()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerWaitOnFRIConnectTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerWaitOnFRIConnectTest, "FRIServerWaitOnFRIConnectTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>GetFRIRequest()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerGetFRIRequestTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerGetFRIRequestTest, "FRIServerGetFRIRequestTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>GetFRIQuality()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerGetFRIQualityTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerGetFRIQualityTest, "FRIServerGetFRIQualityTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>DoCartesianImpedanceControl()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerCartesianImpedanceControlTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerCartesianImpedanceControlTest, "FRIServerCartesianImpedanceControlTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>DoKrlCartesianImpedanceControl()</c> method.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerKrlCartesianImpedanceControlTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerKrlCartesianImpedanceControlTest, "FRIServerKrlCartesianImpedanceControlTest");
        }

        /// <summary>
        /// Test that methods behave properly when FRI server has been closed.
        /// </summary>
        [TestMethod]
        [TestCategory("Unit")]
        [Priority(0)]
        public void FRIServerInvalidFRIRemoteTest()
        {
            KukaLBR4UnitTests.ExecuteNativeTest(NativeFRIServerInvalidFRIRemoteTest, "FRIServerInvalidFRIRemoteTest");
        }

        /// <summary>
        /// Test the basic functionality of the <c>DoNothing()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Test class that exists to wrap PInvokes"), DllImport(
            "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
            EntryPoint = "FRIServerDoNothingTest",
            CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerDoNothingTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test the basic functionality of the <c>DoPositionControl()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
            "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
            EntryPoint = "FRIServerDoPositionControlTest",
            CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerDoPositionControlTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test the basic functionality of the <c>WaitOnConnect()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
           "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
           EntryPoint = "FRIServerWaitOnFRIConnectTest",
           CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerWaitOnFRIConnectTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test the basic functionality of the <c>GetFRIRequest()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
         "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
         EntryPoint = "FRIServerGetFRIRequestTest",
         CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerGetFRIRequestTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test the basic functionality of the <c>GetFRIQuality()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
        "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
        EntryPoint = "FRIServerGetFRIQualityTest",
        CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerGetFRIQualityTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test the basic functionality of the <c>DoCartesianImpedanceControl()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
        "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
        EntryPoint = "FRIServerCartesianImpedanceControlTest",
        CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerCartesianImpedanceControlTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test the basic functionality of the <c>DoKrlCartesianImpedanceControl()</c> method.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
        "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
        EntryPoint = "FRIServerKrlCartesianImpedanceControlTest",
        CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerKrlCartesianImpedanceControlTest(IntPtr resultStringPointer, int bufferSize);

        /// <summary>
        /// Test that methods behave properly when FRI server has been closed.
        /// </summary>
        /// <param name="resultStringPointer">Pointer to a string buffer to store test result in.</param>
        /// <param name="bufferSize">Size of provided buffer.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass", Justification = "Purpose of this class is to wrap PInvokes"), DllImport(
        "Test.Robotics.Hardware.KukaLBR.KukaLBR4NativeTestLib.dll",
        EntryPoint = "FRIServerInvalidFRIRemoteTest",
        CallingConvention = CallingConvention.Cdecl)]
        private static extern void NativeFRIServerInvalidFRIRemoteTest(IntPtr resultStringPointer, int bufferSize);
    }
}
